package com.kgc.activityprovider.config;


import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

@Configuration
public class ActivitiConfiguration implements ProcessEngineConfigurationConfigurer {



    // 存储引擎配置，以供后面使用
    private static SpringProcessEngineConfiguration springProcessEngineConfiguration;

    @Override
    public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
        ActivitiConfiguration.springProcessEngineConfiguration = springProcessEngineConfiguration;

    }

    /**
     * 获取流程引擎配置
     * @return
     */
    public static SpringProcessEngineConfiguration getSpringProcessEngineConfiguration() {
        return springProcessEngineConfiguration;
    }


//    @Autowired
//    private DataSource dataSource;
//    @Autowired
//    private PlatformTransactionManager platformTransactionManager;
//    // 存储引擎配置，以供后面使用
//    private static SpringProcessEngineConfiguration springProcessEngineConfiguration;
//
//    public ActivitiConfiguration() {
//    }
//
//    public static SpringProcessEngineConfiguration getSpringProcessEngineConfiguration() {
//
//        return springProcessEngineConfiguration;
//    }
    //通过@Bean注解将SpringProcessEngineConfiguration实例声明为Spring Bean，使其可供其他组件注入和使用
//    @Bean
//    public SpringProcessEngineConfiguration springProcessEngineConfiguration() {
//        SpringProcessEngineConfiguration spec = new SpringProcessEngineConfiguration();
//        //设置数据源，将注入的数据源设置到SpringProcessEngineConfiguration实例中
//        spec.setDataSource(this.dataSource);
//        //设置事务管理器将注入的事务管理器设置到SpringProcessEngineConfiguration实例中
//        spec.setTransactionManager(this.platformTransactionManager);
//        //设置数据库模式更新策略 true表示在启动时自动创建或更新Activiti引擎所需的数据库表结构
//        spec.setDatabaseSchemaUpdate("true");
////        spec.setDeploymentResources(new Resource[0]);
//        //关闭自动部署
////        spec.setDeploymentMode(DeploymentMode.NONE);
////        Resource[] resources = null;
////        //配置流程部署资源
////        //使用PathMatchingResourcePatternResolver从classpath中的bpmn目录下加载所有以.bpmn为扩展名的文件作为流程定义资源，
////        // 并将它们设置到SpringProcessEngineConfiguration实例中。
////        try {
////            resources = (new PathMatchingResourcePatternResolver()).getResources("classpath*:bpmn/*.bpmn");
////        } catch (IOException var4) {
////            var4.printStackTrace();
////        }
////
////        spec.setDeploymentResources(resources);
//        return spec;
//    }

//    @Override
//    public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
//        ActivitiConfiguration.springProcessEngineConfiguration = springProcessEngineConfiguration;
//    }
}
